package com.mugui.base.client.net.baghandle;


import java.lang.reflect.InvocationTargetException;

import com.mugui.Mugui;
import com.mugui.base.base.ApplicationContext;
import com.mugui.base.client.net.base.ModelInterface;
import com.mugui.base.client.net.bean.Message;
import com.mugui.base.client.net.bean.NetBag;
import com.mugui.base.client.net.classutil.DataSave;


public class NetBagModule implements ModelInterface {

	@Override
	public void stop() {

	}

	@Override
	public void start() {

	}

	@Override
	public boolean isrun() {
		return false;
	}

	private ApplicationContext applicationContext = null;

	@Override
	public void init() {
		if (applicationContext == null)
			applicationContext = (ApplicationContext) DataSave.context;
	}

	public void init(Mugui obj) {
		init();
		object = applicationContext.getBean(obj.getClass());
	}

	Mugui object = null;

	public Message runFunc(NetBag bag)
			throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
		String func[] = bag.getFunc().split("[.]");
		try {
			return (Message) object.invokeFunction(func[func.length - 1], bag);
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}


}
